package com.hzdl.apple.dao.imp.back;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.hzdl.apple.bean.cart.Order;
import com.hzdl.apple.dao.BaseDaoImp;
import com.hzdl.apple.dao.back.BackOrderDao;

public class BackOrderDaoImp extends BaseDaoImp implements BackOrderDao {

	@Override
	public List<Order> getAllOrder() {
		sql = "select * from orderA";
		try {
			return qr.query(sql,new BeanListHandler<>(Order.class));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public int getOrderNum() {
		sql = "select count(*) from orderA";
		try {
			return qr.query(sql,new BeanHandler<>(Integer.class));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;
	}

	@Override
	public boolean updateUser(String oID, Order order) {
		sql = "update orderA set UID = ?,OrderTime = ?,type = ? where OID = ?";
		try {
			qr.update(sql,order.getUID(),order.getOrderTime(),order.getType(),oID);
			return true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public Order getOrderByID(String oID) {
		sql = "select * from user where UID = ?";
		try {
			return qr.query(sql, new BeanHandler<>(Order.class),oID);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public boolean deleteOrder(String oID) {
		sql = "delete from order where OID = ?";
		try {
			qr.update(sql,oID);
			return true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
	
	
	public List<Order> getCanOrder(){
		sql = "select * from orderA where type = 5";
		try {
			return qr.query(sql,new BeanListHandler<>(Order.class));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public boolean updateCanOrder(String oID){
		sql = "update orderA set type = 6 where OID = ?";
		try {
			qr.update(sql,oID);
			return true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
}
